package com.itcat.mapper;

import com.itcat.mysql.pojo.CmsSubjectProductRelation;
import com.itcat.mysql.pojo.PmsProductLadder;
import com.itcat.mysql.pojo.PmsSkuStock;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author 小心触碰的电脑
* @description 针对表【pms_sku_stock(sku的库存)】的数据库操作Mapper
* @createDate 2022-04-03 16:27:38
* @Entity com.itcat.mysql.pojo.PmsSkuStock
*/
@Mapper
public interface PmsSkuStockMapper extends BaseMapper<PmsSkuStock> {

    @Insert({"<script> " +
            "insert into pms_sku_stock  ( product_id, sku_code, stock , price, low_stock, pic, sale, promotion_price, lock_stock , sp_data)values" +
            " <foreach collection='list' item='item' index='index' separator=',' > " +
            "( #{item.productId}, #{item.skuCode}, #{item.stock}, #{item.price}, #{item.lowStock}, #{item.pic}, #{item.sale}, #{item.promotionPrice}, #{item.lockStock}, #{item.spData})" +
            "</foreach>" +
            "</script>"})
    int batchInsert(@Param("list") List<PmsSkuStock> list);


    @Update({"<script> " +
            "<foreach collection='list' item='item' index='index' separator=';'> " +
            "UPDATE pms_sku_stock " +
            "SET sku_code = #{item.skuCode}, price= #{item.price} ,stock = #{item.stock} ,low_stock = #{item.lowStock} " +
            "WHERE id = #{item.id} </foreach> </script>"})
    int batchUpdate(@Param("list") List<PmsSkuStock> list);

    @Update({"<script> " +
            "<foreach collection='list' item='item' index='index' separator=';'> " +
            "UPDATE pms_sku_stock " +
            "SET product_id = #{item.productId}, sku_code=#{item.skuCode}, stock=#{item.stock}, price=#{item.price}, low_stock=#{item.lowStock}, pic=#{item.pic}, sale=#{item.sale}, promotion_price=#{item.promotionPrice}, lock_stock=#{item.lockStock}, sp_data=#{item.spData}  " +
            "WHERE id = #{item.id} </foreach> </script>"})
    int batchUpdateAll(@Param("list") List<PmsSkuStock> list);
}




